function changeWebSite(obj){
	
	
    $.ajax({
        beforeSend: function(){
            $("#overview_table").html('<img src="/images/public/ajax-loader.gif" />');
        },
        type: "POST",
        cache: false,
        url: "/summary/get_overview_table",
        data: {
            website: $(obj).val()
        },
        success: function(data){
            $("#overview_table").html(data);
			$(".tablesorter").tablesorter( {sortList: [[0,0]],widgets: ['zebra']} );
        }
    });
}

function getAccountSettings(obj){
	$.ajax({
        beforeSend: function(){
            $("#overview").html('<img src="/images/public/ajax-loader-bar.gif" />');
        },
        type: "POST",
        cache: false,
		dataType: "json",
        url: "/summary/get_account_settings",
        success: function(data){
			/*
			 * assign css id
			 */
            $("#selected_menu_btn").removeAttr("id");
			$(obj).attr("id", "selected_menu_btn");
			
			/*
			 * remove subterm and reassign
			 */
			$('#subterms').remove();
			$("#account_settings_btn").append(data['account_settings_subterms']);
			$("#overview").html(data['personal_info']);
        }
    });
}

function getChangePassword(obj){
	$.ajax({
        beforeSend: function(){
            $("#overview").html('<img src="/images/public/ajax-loader-bar.gif" />');
        },
        type: "POST",
        cache: false,
        url: "/summary/get_change_password",
        success: function(data){
           	$(".link02").attr('class', 'link01');
          	$(obj).parent().attr('class', 'link02');
			$("#overview").html(data);
        }
    });
}

function changePassword(){
	$.ajax({
		 beforeSend: function(){
            $("#updatemsg").html('<img src="/images/public/ajax-loader-circle.gif" />');
        },
        type: "POST",
		dataType: "json",
        cache: false,
        url: "/summary/change_password",
		data: {
            old_password: $('#old_password').val(),
			new_password: $('#new_password').val(),
			confirm_new_password: $('#confirm_new_password').val()
        },
        success: function(data){
			console.log(data['msg']);
			console.log(data['status']);
			$("#updatemsg").html(data['msg']);
        }
    });
}

function getPersonalInfo(obj){
	$.ajax({
        beforeSend: function(){
            $("#overview").html('<img src="/images/public/ajax-loader-bar.gif" />');
        },
        type: "POST",
        cache: false,
        url: "/summary/get_personal_info",
        success: function(data){
			$(".link02").attr('class', 'link01');
          	$(obj).parent().attr('class', 'link02');
			$("#overview").html(data);
        }
    });
}

function savePersonalInfo(){
	$.ajax({
		 beforeSend: function(){
            $("#updatemsg").html('<img src="/images/public/ajax-loader-circle.gif" />');
        },
        type: "POST",
		dataType: "json",
        cache: false,
        url: "/summary/save_personal_info",
		data: {
            user_name: $('#user_name').val(),
			user_id: $('#user_id').val(),
			user_phone: $('#user_phone').val(),
			user_address: $("#user_address").val()
        },
        success: function(data){
			$("#updatemsg").html(data['msg']);
        }
    });
}

function getOverview(obj){
	$.ajax({
        beforeSend: function(){
            $("#overview").html('<img src="/images/public/ajax-loader-bar.gif" />');
        },
        type: "POST",
        cache: false,
        url: "/summary/get_overview",
        success: function(data){
            /*
             * remove subterms first
             */
			$('#subterms').remove();
			
			$("#selected_menu_btn").removeAttr("id");
			$(obj).attr("id", "selected_menu_btn");
			$(".child01").hide();
			$(obj).siblings('div').show();
			$("#overview").html(data);
			$(".tablesorter").tablesorter( {sortList: [[0,0]],widgets: ['zebra']} );
            
        }
    });
}

function getWebSiteDetail(){
	
	
    $.ajax({
        beforeSend: function(){
            $("#detail_table").html('<img src="/images/public/ajax-loader.gif" />');
        },
        type: "POST",
        cache: false,
        url: "/report_detail/report_detail_table",
		dataType: "json",
        data: {
            website: $('#website').val(),
			start_date: $('#report_date_start').val(),
			end_date: $('#report_date_end').val(),
			chart_type: $("input[name='chart_type']:checked").val()
        },
        success: function(data){
            $("#detail_table").html(data['table_data']);
			$(".tablesorter").tablesorter( {sortList: [[0,0]],widgets: ['zebra']} );
            plotOptions = {
                axes: {
                    xaxis: {
                        renderer: $.jqplot.DateAxisRenderer,
                        tickOptions: {
                            formatString: '%b&nbsp;%#d'
                        }
                    },
                    yaxis: {
						tickOptions: {
                        	formatString: '%d'
                    	},
                        max: data['max_data'],
                        min: data['min_data']
                    }
                },
                highlighter: {
                    show: true,
                    sizeAdjust: 7.5
                }
            };
			$.jqplot('dataChart', data['chart_data'], plotOptions).replot();
        }
    });
}